-
Notifications
You must be signed in to change notification settings - Fork 244
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactoring VariantContextComparator #1629
base: master
Are you sure you want to change the base?
Conversation
* Responding to my own pr comments on #1593 * doing some refactoring to use the Comparator.comparing API * adding a few more tests
@cmnbroad Could you take a look at this, it ended up being more new code than I meant it to be so it probably needs a second pair of eyes. |
blocked because of #1637 |
private final Comparator<VariantContext> internalComparator; | ||
|
||
private static Comparator<VariantContext> makeComparator(final Map<String, Integer> contigIndexLookup) { | ||
return Comparator.comparingInt((VariantContext vc) -> contigIndexLookup.get(vc.getContig())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since you are using a lambda to determine the index given the contig names perhaps that is what you should compose in the constructors:
If the constructor param is a SAMSeqDict then (x) -> dict.getRecord(x).getIndex().
If the constructor param is a List then you create that Map.
Also you can add here the NPE capture into a IAE (or whatever) for missing contigs.
private static class SortedUniquedElementsComparator<T extends Comparable<T>> implements Comparator<Collection<T>>{ | ||
@Override | ||
public int compare(final Collection<T> o1, final Collection<T> o2) { | ||
final Iterator<T> left = new TreeSet<>(o1).iterator(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps is worth to add trivial cases to avoid TreeSet constructons since quite often alt-alleles list are just 1 in length?
@clintval I might have gone a bit overboard on refactoring. I really hate how normal comparators are written and like to rewrite them as the newer Comparator.comparing() chains so I did that.
It's great that you added tests, I ended up condensing them into a single test case with a dataprovider and a few additional use cases. I never would have bothered having any if you hadn't mad them in the first place though!